package com.forum.controller;

import com.forum.bean.Types;
import com.forum.common.Result;
import com.forum.service.TypesService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/types")
public class TypesController {
    private final TypesService typesService;
    public TypesController(TypesService typesService) {
        this.typesService = typesService;
    }

    /**
     * 获取所有类型
     * GET /api/types
     */
    @GetMapping("/all")
    public Result<List<Types>> getAllTypes() {
        return Result.ok(typesService.getAllTypes());
    }

    /**
     * 添加类型
     * POST /api/types
     */
    @PostMapping("/add")
    public Result<String> addType(String typeName) {
        typesService.addType(typeName);
        return Result.ok("添加成功");
    }

    /**
     * 删除类型
     * DELETE /api/types/{id}
     */
    @DeleteMapping("/{id}")
    public  Result<String>  deleteType(@PathVariable("id") Integer typeId) {
        typesService.deleteType(typeId);
        return Result.ok("添加成功");
    }


}
